package net.lainiao.morethread.Chapter1.demo4;

import java.util.Date;
import java.util.Deque;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/2/27.
 */
public class WriterTask implements Runnable {
    private Deque<Event> deque;
    public WriterTask(Deque<Event> deque){
        this.deque=deque;
    }

    @Override
    public void run() {
        for (int i = 0; i <100 ; i++) {
            Event event=new Event();
            event.setActionDate(new Date());
            event.setEventName(String.format("Thread thread %s has generated an event",Thread.currentThread().getId()));
            deque.addFirst(event);
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
